<!--
 * @Autor: wanghan
 * @Date: 2022-01-06 14:07:59
 * @LastEditors: 黄威
 * @LastEditTime: 2022-01-14 14:17:49
 * @Description: 地图书签组件
-->

<template>
    <MgsBookmark
        v-loading="loading"
        :bind-map="bindMap"
        :load-handle="getBookmarkList"
        :add-handle="addBookmark"
        :remove-handle="removeBookmark"
    />
</template>

<script>
import MgsBookmark from '@mgs/components/mgs-bookmark/mgs-bookmark.vue';
import MapAPI from '@/apis/mapApi';

export default {
    components: { MgsBookmark },
    props: {
        bindMap: Object,
    },
    data() {
        return {
            // 加载状态
            loading: true,
            // arr
            bookmarkData: null,
            pageSize: 100,
            pageNum: 1,
            pageTotal: 100,
        };
    },
    created() {
        // 获取书签列表
        this.getBookmarkList();
    },
    methods: {
        // 获取书签列表
        getBookmarkList(params, callback) {
            MapAPI.getBookmarkList({
                pageSize: this.pageSize,
                pageNum: this.pageNum,
            })
                .then(res => {
                    callback ? callback(res.list || []) : '';
                })
                .finally(() => (this.loading = false));
        },
        // 添加标签
        addBookmark(params, callback) {
            MapAPI.addBookmark(params).then(res => {
                callback ? callback(res || '') : '';
            });
        },
        // 删除标签
        removeBookmark(params, callback) {
            MapAPI.removeBookmark({
                data: params,
            }).then(res => {
                callback ? callback(res) : '';
            });
        },
    },
};
</script>
